package com.sz.mes.controller;

import com.sz.mes.dto.ClockInDTO;
import com.sz.mes.entity.*;
import com.sz.mes.vo.GenerateTechniqueVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.diboot.core.vo.*;
import com.diboot.iam.annotation.OperationCons;
import com.diboot.iam.annotation.BindPermission;
import com.diboot.iam.annotation.Log;
import com.sz.mes.dto.ReworkClockInDTO;
import com.sz.mes.vo.ReworkClockInListVO;
import com.sz.mes.vo.ReworkClockInDetailVO;
import com.sz.mes.service.ReworkClockInService;
import com.sz.mes.controller.BaseCustomCrudRestController;

import lombok.extern.slf4j.Slf4j;
import javax.validation.Valid;
import java.util.List;

/**
 * 返工上下机记录 相关Controller
 *
 * @author hem
 * @version 1.0
 * @date 2024-10-26
 * Copyright © szhs
 */
@RestController
@RequestMapping("/reworkClockIn")
@BindPermission(name = "返工上下机记录")
@Slf4j
public class ReworkClockInController extends BaseCustomCrudRestController<ReworkClockIn> {
    @Autowired
    private ReworkClockInService reworkClockInService;

    /**
     * 查询ViewObject的分页数据
     * <p>
     * url请求参数示例: /list?field=abc&pageIndex=1&orderBy=abc:DESC
     * </p>
     *
     * @return
     * @throws Exception
     */
    @Log(operation = OperationCons.LABEL_LIST)
    @BindPermission(name = OperationCons.LABEL_LIST, code = OperationCons.CODE_READ)
    @GetMapping("/list")
    public JsonResult getViewObjectListMapping(ReworkClockInDTO queryDto, Pagination pagination) throws Exception{
    		return super.getViewObjectList(queryDto, pagination, ReworkClockInListVO.class);
    }   

    /**
     * 根据资源id查询ViewObject
     *
     * @param id ID
     * @return
     * @throws Exception
     */
    @Log(operation = OperationCons.LABEL_DETAIL)
    @BindPermission(name = OperationCons.LABEL_DETAIL, code = OperationCons.CODE_READ)
    @GetMapping("/{id}")
    public JsonResult getViewObjectMapping(@PathVariable("id")Long id) throws Exception{
        return super.getViewObject(id, ReworkClockInDetailVO.class);
    }

    /**
     * 创建资源对象
     *
     * @param entity
     * @return JsonResult
     * @throws Exception
     */
    @Log(operation = OperationCons.LABEL_CREATE)
    @BindPermission(name = OperationCons.LABEL_CREATE, code = OperationCons.CODE_WRITE)
    @PostMapping("/")
    public JsonResult createEntityMapping(@Valid @RequestBody ReworkClockIn entity) throws Exception {
        return super.createEntity(entity);
    }

    /**
     * 根据ID更新资源对象
     *
     * @param entity
     * @return JsonResult
     * @throws Exception
     */
    @Log(operation = OperationCons.LABEL_UPDATE)
    @BindPermission(name = OperationCons.LABEL_UPDATE, code = OperationCons.CODE_WRITE)
    @PutMapping("/{id}")
    public JsonResult updateEntityMapping(@PathVariable("id")Long id, @Valid @RequestBody ReworkClockIn entity) throws Exception {
        return super.updateEntity(id, entity);
    }

    /**
     * 根据id删除资源对象
     *
     * @param id
     * @return
     * @throws Exception
     */
    @Log(operation = OperationCons.LABEL_DELETE)
    @BindPermission(name = OperationCons.LABEL_DELETE, code = OperationCons.CODE_WRITE)
    @DeleteMapping("/{id}")
    public JsonResult deleteEntityMapping(@PathVariable("id")Long id) throws Exception {
        return super.deleteEntity(id);
    }

    /**
     * 生成工序任务
     *
     * @param
     * @return JsonResult
     * @throws Exception
     */
    @Log(operation = OperationCons.LABEL_CREATE)
    // @BindPermission(name = OperationCons.LABEL_CREATE, code = OperationCons.CODE_WRITE)
    @PostMapping("/generateTechnique")
    public JsonResult generateTechnique(@Valid @RequestBody GenerateTechniqueVO generateTechniqueVO) throws Exception {
        return reworkClockInService.generateTechnique(generateTechniqueVO);
    }

    /**
     * 上机
     *
     * @param
     * @return JsonResult
     * @throws Exception
     */
    @Log(operation = OperationCons.LABEL_CREATE)
    // @BindPermission(name = OperationCons.LABEL_CREATE, code = OperationCons.CODE_WRITE)
    @PostMapping("/upplane")
    public JsonResult upplane(@Valid @RequestBody ReworkClockIn reworkClockIn) throws Exception {
        return reworkClockInService.upplane(reworkClockIn);
    }

    /**
     * 下机
     *
     * @param
     * @return JsonResult
     * @throws Exception
     */
    @Log(operation = OperationCons.LABEL_CREATE)
    // @BindPermission(name = OperationCons.LABEL_CREATE, code = OperationCons.CODE_WRITE)
    @PostMapping("/deplane")
    public JsonResult deplane(@Valid @RequestBody ReworkClockInDTO reworkClockInDTO) throws Exception {
        return reworkClockInService.deplane(reworkClockInDTO);
    }

    /**
     * 结束加工任务
     *
     * @param
     * @return JsonResult
     * @throws Exception
     */
    @Log(operation = OperationCons.LABEL_UPDATE)
    // @BindPermission(name = OperationCons.LABEL_UPDATE, code = OperationCons.CODE_WRITE)
    @PostMapping("/executeState")
    public JsonResult executeState(@Valid @RequestBody ReworkClockIn reworkClockIn) throws Exception {
        return reworkClockInService.executeState(reworkClockIn);
    }

    /**
     * 查询加工任务下的详细信息
     *
     *  @return
     *  @throws Exception
     */
    @Log(operation = OperationCons.LABEL_LIST)
    // @BindPermission(name = OperationCons.LABEL_LIST, code = OperationCons.CODE_READ)
    @PostMapping("/findProductDetail")
    public JsonResult findProductDetail(@RequestBody ReworkClockIn reworkClockIn) throws Exception {
        return reworkClockInService.findProductDetail(reworkClockIn);
    }

    /**
     * 查询加工任务列表
     *
     *  @return
     *  @throws Exception
     */
    @Log(operation = OperationCons.LABEL_LIST)
    // @BindPermission(name = OperationCons.LABEL_LIST, code = OperationCons.CODE_READ)
    @GetMapping("/findTaskList")
    public JsonResult findTaskList(Integer state) throws Exception {
        return reworkClockInService.findTaskList(state);
    }

    /**
     * 根据设备信息查询返工任务单
     *
     * @param
     * @return
     */
    @Log(operation = OperationCons.LABEL_LIST)
    // @BindPermission(name = OperationCons.LABEL_LIST, code = OperationCons.CODE_READ)
    @PostMapping("/getTaskInfo")
    public JsonResult getTaskInfo(@RequestBody Equipment equipment) {
        return reworkClockInService.getTaskInfo(equipment);
    }


} 